<template>
    <div class="child2">

        <h2>子组件2</h2>
        <h2>aa:====={{ aa }}</h2>
        <h2>bb:====={{ bb }}</h2>
        <h2>$attrs:====={{ $attrs }}</h2>
        <button @click="chefn(6)">inject传方法</button>
        <h2>子组件2</h2>
        <h2>兄弟组件给的玩具-----》{{ childtoy }}</h2>
        <h2>provide的车-----》{{ car }}</h2>
        code: <input type="text" :value="code" @input="codecahange">
        <br>
        age: <input type="text" :value="age" @input="agecahange">
        <Sun v-bind="$attrs" />
    </div>

</template>

<script lang='ts' setup>
import emitter from '@/utils/emitter';
import Sun from "./sun.vue"
import { inject, ref } from 'vue'
let childtoy = ref("")
let props = defineProps(["code", "age", "aa", "bb"])
let emit = defineEmits(["update:code", "update:age"])
let car = inject("che", "奔驰")//第二个值是默认值
let chefn: any = inject("chefn")

emitter.on("gettoy", (value: any) => {
    console.log(888888, value);
    childtoy.value = value
})
const codecahange = (e: any) => {
    emit("update:code", e.target.value)
}
const agecahange = (e: any) => {
    emit("update:age", e.target.value)
}

</script>
<style scoped>
.child2 {
    width: 500px;
    height: 700px;
    background: rgb(225, 152, 152);
}
</style>